package com.hbxs.folder.constant;

import cn.hutool.core.util.StrUtil;

import java.util.Arrays;
import java.util.concurrent.atomic.AtomicReference;

/**
 * 文件类型
 */
public enum FolderTypeEnum {

    IMG("Img","BMP,PNG,JPG,JPEG,GIF,TIF"),
    VIDEO("Video","AVI,MOV,RMVB,RM,FLV,MP4,3GP"),
    Excel("Excel","XLSX,XLS,CSV,XLSM,XLTX,XLTM,XLSB,XLAM"),
    Word("Word","DOCX,DOCM,DOTX,DOTM"),
    PPT("PPT","PPTX,PPTM,PPSX,PPSX,POTX,POTM,PPAM"),
    Document("Document","PDF,TXT,XML,HTML"),
    Forbid("Forbid",".12314"),
    OTHER("other","*");


    private String name;

    private String suffix;

    FolderTypeEnum(String name, String suffix) {
        this.name = name;
        this.suffix = suffix;
    }

    public String getName() {
        return name;
    }

    public String getSuffix() {
        return suffix;
    }

    public static String getFolderType(String suffix){
        AtomicReference<String> type = new AtomicReference<>(FolderTypeEnum.OTHER.getName());
        Arrays.asList(FolderTypeEnum.values()).forEach(
                next ->{
                    if (StrUtil.containsIgnoreCase(next.getSuffix(),suffix)){
                        type.set(next.getName());
                    }
                }
        );
        return type.get();
    }

}
